﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;

namespace Tomahawk.Runtime.Timeline
{
    public class BoolKey : Key
    {
        [XmlAttribute("Value")]
        public bool value;

        public BoolKey() { }
        public BoolKey(float time, bool value) : base(time) { this.value = value; }
    }

    public class BoolTrack : Track<BoolKey>
    {
        public BoolTrack() { }

        public BoolTrack(string name) : base(name) { }

        protected bool SetValue(Boolean value)
        {
            if (this.fieldInfo != null)
            {
                this.fieldInfo.SetValue(this.target, value);
                return true;
            }

            if (this.propertyInfo != null)
            {
                this.propertyInfo.SetValue(this.target, value, null);
                return true;
            }

            return false;
        }

        protected override bool InterpolateLerp(BoolKey lowerKey, BoolKey upperKey, float alpha)
        {
            Boolean value = alpha > 0.5 ? upperKey.value : lowerKey.value;
            return SetValue(value);
        }

        protected override bool InterpolateSpline(BoolKey lowerKey, BoolKey upperKey, float alpha)
        {
            Boolean value = alpha > 0.5 ? upperKey.value : lowerKey.value;
            return SetValue(value);
        }
    }
}
